home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
cenvid
/
os2sessn.cmm
< prev
next >
Wrap
Text File
|
1995-09-27
|
6KB
|
174 lines
// OS2Sessn.cmm - start a session in OS/2 and then return
// ver.2 from DOS or Windows
if ( !defined(_DOS_) && !defined(_WINDOWS_) && !defined(_DOS32_) ) {
printf("\a\n");
puts("OS2Sessn.cmm starts session from within DOS or Windows")
puts("running under OS/2, and must be executed from CEnvi for")
puts("DOS or CEnvi for Windows");
exit(EXIT_FAILURE);
}
Instructions()
{
printf("\a\n");
puts(`OS2Sessn - Start an OS/2 session from DOS or Windows under OS/2`)
puts(``)
puts(`USAGE: CEnvi OS2Sessn <D|O|P|E|S><W|F><C|I><F|B><E|N> [Commands]`)
puts(``)
puts(`WHERE: D,O,P,E,S - DOS, OS/2, PM, Enhance Windows, or Standard Windows`)
puts(` W,F - Windowed or Full-Screen`)
puts(` C,I - Child or Independent; if child then return when child done`)
puts(` F,B - Foreground or Background`)
puts(` E,N - Environment inherited or no inherit environment`)
puts(` Commands - Any command to pass on. Any two single qotes together ('')`)
puts(` row will be replace by a double quote(")`)
puts(``)
puts(`EXAMPLES: CEnvi OS2Sessn DFCFE edit.com c:\autoexec.bat`)
puts(` CEnvi OS2Sessn OFIBN CMD.EXE SESSION /W /WIN /F WINFILE.EXE`)
puts(` CEnvi OS2Sessn DFIBN COMPILE.EXE FOO.MAK`)
if ( defined(_WINDOWS_) && !defined(_SHELL_) ) {
printf("Press any key to exit...");
getch();
}
exit(EXIT_FAILURE);
}
main(argc,argv)
{
if ( argc < 2 || 5 != strlen(Flags=strupr(argv[1])) ) {
printf("\nUnknown flags (First parameter).\n");
Instructions();
}
if ( !strchr("DOPES",SessionType=Flags[0]) ) {
printf("\nUnknown Session Type \"%c\", must be D, O, P, E, or S\n",SessionType);
Instructions();
}
if ( !strchr("WF",SessionSize=Flags[1]) ) {
printf("\nUnknown Session Size \"%c\", must be W or F\n",SessionSize);
Instructions();
}
if ( !strchr("CI",SessionRelation=Flags[2]) ) {
printf("\nUnknown Session Relation \"%c\", must be C or I\n",SessionRelation);
Instructions();
}
if ( !strchr("FB",SessionPriority=Flags[3]) ) {
printf("\nUnknown Session Priority \"%c\", must be F or B\n",SessionPriority);
Instructions();
}
if ( !strchr("EN",SessionEnvironment=Flags[4]) ) {
printf("\nUnknown Session Environment \"%c\", must be E or N\n",SessionEnvironment);
Instructions();
}
BuildCommand(argc-2,argv+2,Title,Program,Parameters);
StartData = BuildStartData(SessionType,SessionSize,SessionRelation,SessionPriority,
SessionEnvironment,Title,Program,Parameters);
// call the interrupt to start this block
reg.ah = 0x64;
reg.bx = 0x25; // API ordinal
reg.ch = 'c', reg.cl = 'l';
if !defined(_DOS32_)
reg.ds = segment(StartData), reg.si = offset(StartData);
else
reg.dx = pointer(StartData);
interrupt(0x21,reg);
}
BuildStartData(Type,Size,Relationship,Priority,Environment,Title,Program,Parameters)
{
BLObPut(sdata,0,UWORD16); // size of structure, add later
BLObPut(sdata,Relationship == 'C' ? 1 : 0,UWORD16);
BLObPut(sdata,Priority == 'F' ? 0 : 1,UWORD16);
BLObPut(sdata,0,UWORD16); // no trace
BLObPut(sdata,Title ? pointer(Title) : NULL,UWORD32);
if ( Type == 'E' || Type == 'S' ) {
// windows program start WIN.COM
if ( Program ) {
if ( Parameters )
sprintf(Parameters,"%s %s",Program,Parameters);
else
strcpy(Parameters,Program);
}
if ( Type == 'E' ) {
if ( Parameters )
sprintf(Parameters,"/3 %s",Parameters);
else
Parameters = "/3";
}
Program = "WIN.COM";
}
BLObPut(sdata,Program ? pointer(Program) : NULL,UWORD32);
BLObPut(sdata,Parameters ? pointer(Parameters) : NULL,UWORD32);
BLObPut(sdata,0,UWORD32); // TERMQ
BLObPut(sdata,0,UWORD32); // pointer to environment
BLObPut(sdata,Environment == 'E' ? 1 : 0,UWORD16);
// finally, determine program type
#define SESSION_DEFAULT 0
#define SESSION_OS2_FULLSCREEN 1
#define SESSION_WINDOWABLEVIO 2
#define SESSION_PM 3
#define SESSION_DOS_FULLSCREEN 4
#define SESSION_DOS_WINDOWED 7
switch( Type ) {
case 'D':
SessionType = ( Size == 'F' ? SESSION_DOS_FULLSCREEN : SESSION_DOS_WINDOWED );
break;
case 'O':
SessionType = ( Size == 'F' ? SESSION_OS2_FULLSCREEN : SESSION_WINDOWABLEVIO );
break;
case 'P':
SessionType = 3;
break;
case 'E':
case 'S':
if ( Size == 'F' ) {
SessionType = SESSION_DOS_FULLSCREEN;
break;
}
printf("\a\nOS2Sessn does not directly start Windows in Seamless mode.\n")
printf("You may try starting and OS/2 session with a START or SESSION\n");
printf("command.\n");
if ( defined(_WINDOWS_) ) {
printf("Press any key to exit...");
getch();
}
exit(EXIT_FAILURE);
}
BLObPut(sdata,SessionType,UWORD16);
// go back and add size
BLObPut(sdata,0,BLObSize(sdata),UWORD16);
return sdata;
}
BuildCommand(argc,argv,Title,Program,Parameters)
{
if ( !argc ) {
Program = Parameters = Title = NULL;
} else {
Program = argv[0];
// build title as root name of command
Title = SplitFileName(Program).name;
if ( argc == 1 )
Parameters = NULL;
else {
Parameters = "";
for ( i = 1; i < argc; i++ ) {
strcat(Parameters," ");
strcat(Parameters,argv[i]);
}
Parameters;
// turn any double single-quotes into a double-quote
s = Parameters;
while ( s = strstr(s,"\'\'") ) {
strcpy(s,s+1);
s[0] = '\"';
}
}
}
}